#coding=utf-8
#win32 com api :http://msdn.microsoft.com/en-us/library/aa752085(VS.85).aspx
import win32com.client, pythoncom
import time

class EventHandler:
    def OnDownloadBegin(self):
        print "下载网页"
    def OnDownloadComplete(self):
        print "下载完毕"
    #def OnDocumentComplete(self):
    #    print "网页载入完毕"
    def OnBeforeNavigate(self):
        print "准备导航"
    def OnNavigateComplete(self):
        print "导航结束"
    def OnNavigateError(self):
        print "导航错误"
    def OnNewWindow(self): 
        print "打开新窗口"   
    def OnWindowClosing(self):
        print "窗口关闭"
        
#ie = win32com.client.DispatchEx('InternetExplorer.Application.1')
ie = win32com.client.DispatchWithEvents('InternetExplorer.Application.1',EventHandler)
ie.Visible = 1
ie.Navigate("http://www.yntrip.com/yanyu")
while ie.Busy:
  time.sleep(0.05)

doc = ie.Document
print "输出所有图像"
for i in doc.images:
    print i.src, i.width, i.height
print "输出所有链接"    
for i in doc.getElementsByTagName("a"):
    print i.href
    
#ie.Quit()
    
